﻿#region Summary

// 
// Owner : JackieHan 
// 
// Solution : Erp 
// 
// Project : Jackie.Utility.BvConversion
// 
// File : EnumStringValueConversion.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 枚举和String 转换
// 
// History : 
//			2012-05-15 11:29:38	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;

#endregion

namespace Jackie.Utility.BvConversion.DefalutValueConversion
{
    ///<summary>
    ///枚举和String 转换
    ///</summary>
    public class EnumStringValueConversion : IValueConversion
    {
        private Type enumType;

        public EnumStringValueConversion(Type enumType)
        {
            this.enumType = enumType;
        }

        #region Implementation of IValueConversion

        public object GetViewValue(object businessValue)
        {
            //if (!typeof(TEnum).IsEnum) throw new ArgumentException("businessValue is not a Enum Type!");
            return businessValue.ToString();
        }

        public object GetBusinessValue(object viewValue)
        {
            //if (!typeof(TEnum).IsEnum) throw new ArgumentException("businessValue is not a Enum Type!");
            return Enum.Parse(enumType, viewValue.ToString());
        }

        #endregion
    }
}